home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / xpkmaster.h < prev    next >
C/C++ Source or Header  |  1998-08-27  |  10KB  |  261 lines

  1. #ifndef XPKMASTER_XPKMASTER_H
  2. #define XPKMASTER_XPKMASTER_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        xpkmaster.h
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xpkmaster.h 1.14 (25.06.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15.  1.1   27.12.96 : removed library protos - call now via library interface,
  16.      allows patching
  17.  1.2   30.01.97 : change of cchecksum proto
  18.  1.3   31.01.97 : checksum changed again
  19.  1.4   01.03.97 : added new flags
  20.  1.5   08.03.97 : changed XpkBuffer a bit
  21.  1.6   31.03.97 : some little corrections
  22.  1.7   02.04.97 : removed obsolete stuff
  23.  1.8   12.04.97 : added DebugTagList
  24.  1.9   14.08.97 : fixed defines
  25.  1.10  20.12.97 : changed a lot in defines and structures
  26.  1.11  09.01.98 : added better key-fields to xbuf
  27.  1.12  24.01.98 : removed PP support --> done by xfdmaster now
  28.  1.13  21.02.98 : added code independence
  29.  1.14  25.06.98 : now uses SDI_compiler.h
  30. */
  31.  
  32. /* To disable PowerPacker support comment out the next line. */
  33. /* #define USE_POWERPACKER */
  34.  
  35. #ifdef SUPPORT_A4
  36.   #define A4SUPP    ,a4
  37.   #define A4SUPP2    ,xbuf->xb_regA4
  38.   #define A4PROTO    ,REG(a4, ULONG a4)
  39. #else
  40.   #define A4SUPP
  41.   #define A4SUPP2
  42.   #define A4PROTO
  43. #endif
  44.  
  45. #ifndef XPK_ALLINONE /* This allows some optimizations, when All.c is used */
  46.   #define XPK_ALLINONE
  47. #endif
  48.  
  49. #define SDI_TO_ANSI
  50. #include "SDI_ASM_STD_protos.h"
  51. #include "SDI_compiler.h"
  52.  
  53. #include <xpk/xpk.h>
  54. #include <xpk/xpksub.h>
  55.  
  56. typedef ASM(ULONG) (*regfunc) (REG(a0, struct Hook *),
  57.                    REG(a1, APTR), REG(a2, APTR) A4PROTO);
  58.  
  59. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  60. #define DEFAULTCHUNKSIZE    0x8000
  61.  
  62. #ifndef Min
  63.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  64.   #define max(a,b) ((a) > (b) ? (a) : (b))
  65. #endif
  66.  
  67. /* The structure used for I/O, special master library version */
  68. struct XpkMasterMsg {
  69.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  70.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  71.   LONG   xmm_Size;        /* The size of the read/write        */
  72.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  73.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  74.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  75.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  76.   ULONG  xmm_BufLen;
  77.   ULONG  xmm_BufOfs;
  78.   ULONG  xmm_Len;
  79.   ULONG  xmm_Flags;
  80.   ULONG  xmm_FH;
  81.   ULONG  xmm_MemType;
  82.   STRPTR xmm_FileName;
  83. };
  84.  
  85. #define XIO_GETOUTBUF 1        /* flag for xmm_Flags - allocate buffer    */
  86.  
  87. /* These structures define the file format for compressed streams */
  88. struct XpkStreamHeader {
  89.   ULONG xsh_Pack;
  90.   ULONG xsh_CLen;
  91.   ULONG xsh_Type;
  92.   ULONG xsh_ULen;
  93.   UBYTE xsh_Initial[16];
  94.   UBYTE xsh_Flags;
  95.   UBYTE xsh_HChk;
  96.   UBYTE xsh_SubVrs;
  97.   UBYTE xsh_MasVrs;
  98. };
  99.  
  100. #define XPK_COOKIE    0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  101. #define ROW_OF_MINUS    0x2d2d2d2d    /* '----' */
  102. #define PP_COOKIE    0x50503230    /* 'PP20' */
  103. #define XFD_COOKIE    0x58464444    /* 'XFDD' */
  104. #define USER_COOKIE    0x55534552    /* 'USER' */
  105.  
  106. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  107. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  108. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  109.  
  110. struct XpkChunkHdrWord {
  111.   UBYTE xchw_Type;
  112.   UBYTE xchw_HChk;
  113.   UWORD xchw_CChk;
  114.   UWORD xchw_CLen;
  115.   UWORD xchw_ULen;
  116. };
  117.  
  118. struct XpkChunkHdrLong {
  119.   UBYTE xchl_Type;
  120.   UBYTE xchl_HChk;
  121.   UWORD xchl_CChk;
  122.   ULONG xchl_CLen;
  123.   ULONG xchl_ULen;
  124. };
  125.  
  126. typedef union {
  127.   struct XpkChunkHdrLong xch_Long;
  128.   struct XpkChunkHdrWord xch_Word;
  129. } XpkChunkHeader;
  130.  
  131. #define XPKCHUNK_RAW        0x00 /* raw copy of source */
  132. #define XPKCHUNK_PACKED        0x01 /* packed data */
  133. #define XPKCHUNK_END        0x0F /* empty end Chunk */
  134.  
  135. struct Headers {
  136.   struct XpkStreamHeader h_Glob;
  137.   XpkChunkHeader     h_Loc;
  138.   ULONG             h_LocSize;
  139. };
  140.  
  141. #define XPKMODE_UPUP    1
  142. #define XPKMODE_UPSTD   2
  143. #define XPKMODE_UPPP    3
  144. #define XPKMODE_UPXFD    4
  145. #define XPKMODE_PKSTD  20
  146.  
  147. #define AUTO_PASS_SIZE    50
  148.  
  149. /* This is what XPK "handles" really point to */
  150. struct XpkBuffer {
  151.   struct XpkFib    xb_Fib;        /* file info about this file        */
  152.   UWORD   xb_PackingMode;    /* desired packing efficiency, 0..100   */
  153.   struct Headers xb_Headers;    /* global and local file header     */
  154.   ULONG   xb_Format;        /* type of file                */
  155.   LONG    xb_Result;        /* error code from last call        */
  156.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  157.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  158.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  159.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  160.   ULONG   xb_Secs;        /* Start time, the seconds        */
  161.   ULONG   xb_Mics;        /* Start time, the micros        */
  162.   struct Hook * xb_RHook;    /* input data hook            */
  163.   struct Hook * xb_WHook;    /* output data hook            */
  164.   struct Hook * xb_ChunkHook;    /* Hook to call between chunks        */
  165.   STRPTR  xb_Password;        /* password for de/encoding        */
  166.   ULONG   xb_PasswordSize;    /* password buffer size for own password*/
  167.   ULONG   xb_PassKey32;        /* password key, 32 bit            */
  168.   UWORD   xb_PassKey16;        /* password key, 16 bit            */
  169.   WORD    xb_Priority;        /* task pri during packing        */
  170.   ULONG   xb_SubID;        /* currently active sub ID        */
  171.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  172.   ULONG   xb_FirstChunk;    /* First chunk size - largest chunk    */
  173.   ULONG   xb_Flags;        /* private for xpkmaster        */
  174.   ULONG   xb_InLen;        /* Number of bytes to (un)pack        */
  175.   STRPTR  xb_LastMsg;        /* The last progress message        */
  176.   struct xfdBufferInfo * xb_xfd;/* xfdBufferInfo            */
  177.   struct XpkInfo * xb_SubInfo;    /* Info of current open sub-lib        */
  178.   struct Library * xb_SubBase;    /* Currently open sub-library        */
  179.   struct XpkMasterMsg xb_RMsg;    /* Parameters for reading        */
  180.   struct XpkMasterMsg xb_WMsg;    /* Parameters for writing        */
  181.   struct XpkSubParams xb_PackParam;/* Parameters to (Un)PackChunk()    */
  182.   struct XpkProgress  xb_Prog;    /* Parameters to progress report    */
  183. #ifdef SUPPORT_A4
  184.   ULONG      xb_regA4;
  185. #endif
  186. };
  187.  
  188. /* Values for MasterFlags */
  189. #define XMF_PRIVFH    (1<< 0)    /* We opened the FH, so we close it.    */
  190. #define XMF_PACKING    (1<< 1)    /* This is a packing operation.        */
  191. #define XMF_PASSTHRU    (1<< 2)    /* Pass uncompressed data through    */
  192. #define XMF_GETOUTBUF    (1<< 3)    /* Get output buffer when size known    */
  193. #define XMF_NOCLOBBER    (1<< 4)    /* Don't overwrite            */
  194. #define XMF_EOF        (1<< 5)    /* End of file                */
  195. #define XMF_INITED    (1<< 6)    /* Sublib buffers have been allocted    */
  196. #define XMF_GLOBHDR    (1<< 7)    /* GlobHdr is already written        */
  197. #define XMF_LOSSYOK    (1<< 8)    /* Lossy compression permitted        */
  198. #define XMF_OWNTASKPRI    (1<< 9) /* Altered task pri, restore        */
  199. #define XMF_NOCRC    (1<<10)    /* Do not check the checksum on decomp    */
  200. #define XMF_NOPREFS    (1<<11) /* Are prefs allowed ?            */
  201. #define XMF_XFD        (1<<12) /* Is XFD unpacking allowed ?        */
  202. #define XMF_EXTERNALS    (1<<13) /* Is extern allowed ?            */
  203. #define XMF_AUTOPASSWD    (1<<14) /* Automatic password            */
  204. #define XMF_AUTOPRHOOK  (1<<15) /* Automatic Progress hook        */
  205. #define XMF_NOPACK    (1<<16) /* destination file equals source    */
  206. #define XMF_OWNPASSWORD (1<<17) /* free password buffer later !!!    */
  207. #define XMF_KEY16    (1<<18) /* got a 16 bit key (needed, as key may */
  208. #define XMF_KEY32    (1<<19) /* got a 32 bit key  be 0 - no check)   */
  209.  
  210. #ifdef DEBUG
  211. void     DebugError(STRPTR, ...);            /* debug.c */
  212. void     DebugRunTime(STRPTR, ...);            /* debug.c */
  213. void    DebugTagList(STRPTR, struct TagItem *);        /* debug.c */
  214. #endif
  215.  
  216. extern struct DosLibrary       *DOSBase;        /* libinit.a */
  217. extern struct Hook        fhinhook;        /* hook_fh.c */
  218. extern struct Hook        fhouthook;        /* hook_fh.c */
  219. extern struct IntuitionBase    *IntuitionBase;        /* libinit.a */
  220. extern struct Hook        meminhook;        /* hook_mem.c */
  221. extern struct Hook        memouthook;        /* hook_mem.c */
  222. extern struct ExecBase         *SysBase;        /* libinit.a */
  223. extern struct UtilityBase      *UtilityBase;        /* libinit.a */
  224. extern struct Library           *XpkBase;        /* libinit.a */
  225.  
  226. XPK_ALLINONE LONG    callprogress(struct XpkBuffer *);            /* progress.c */
  227. XPK_ALLINONE UWORD    cchecksum(ULONG *, ULONG);                /* checksum.c */
  228. XPK_ALLINONE void    closesub(struct XpkBuffer *);                /* sublibs.c */
  229. XPK_ALLINONE LONG    freebufs(struct XpkBuffer *);                /* xbuf.h */
  230. XPK_ALLINONE struct XpkPrefsSemaphore *    GetPrefsSem(void);            /* objects.c */
  231. XPK_ALLINONE UBYTE    hchecksum(STRPTR, ULONG);                /* checksum.c */
  232. XPK_ALLINONE APTR    hookread(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  233. XPK_ALLINONE APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  234. XPK_ALLINONE ULONG    idfromname(STRPTR);                    /* sublibs.c */
  235. XPK_ALLINONE struct XpkBuffer *        initxbuf(void);                /* xbuf.h */
  236. XPK_ALLINONE struct Library *        opensub(struct XpkBuffer *, ULONG);    /* sublibs.c */
  237. XPK_ALLINONE LONG    parsebuftags(struct XpkBuffer*, struct TagItem*);    /* tags.c */
  238. XPK_ALLINONE LONG    parseerrortags(struct TagItem *, LONG);            /* tags.c */
  239. XPK_ALLINONE void    parsegettags(struct XpkBuffer *);            /* tags.c */
  240. XPK_ALLINONE void    percentages(struct XpkFib *);                /* fib.c */
  241. XPK_ALLINONE void    updatefib(struct XpkBuffer *);                /* fib.c */
  242. XPK_ALLINONE ASM(LONG)    xpkopen(REG(a0, struct XpkBuffer **),
  243.             REG(a1, struct TagItem *), REG(d2,ULONG) A4PROTO);    /* open.c */
  244.  
  245. ASM(LONG)  LIBXpkExamine(REG(a0, struct XpkFib *), REG(a1, struct TagItem *) A4PROTO);
  246. ASM(LONG)  LIBXpkPack(REG(a0, struct TagItem *) A4PROTO);
  247. ASM(LONG)  LIBXpkUnpack(REG(a0, struct TagItem *) A4PROTO);
  248. ASM(LONG)  LIBXpkOpen(REG(a0, struct XpkBuffer **), REG(a1, struct TagItem *) A4PROTO);
  249. ASM(LONG)  LIBXpkRead(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  250. ASM(LONG)  LIBXpkWrite(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  251. ASM(LONG)  LIBXpkSeek(REG(a0, struct XpkBuffer *), REG(d0, LONG), REG(d1, ULONG));
  252. ASM(LONG)  LIBXpkClose(REG(a0, struct XpkBuffer *));
  253. ASM(LONG)  LIBXpkQuery(REG(a0, struct TagItem *));
  254. ASM(APTR)  LIBXpkAllocObject(REG(d0, ULONG), REG(a0, struct TagItem *));
  255. ASM(void)  LIBXpkFreeObject(REG(d0, ULONG), REG(a0, APTR));
  256. ASM(BOOL)  LIBXpkPrintFault(REG(d0, LONG), REG(a0, STRPTR));
  257. ASM(ULONG) LIBXpkFault(REG(d0, LONG), REG(a0, STRPTR), REG(a1, STRPTR), REG(d1, ULONG));
  258. ASM(LONG)  LIBXpkPassRequest(REG(a0, struct TagItem *));
  259.  
  260. #endif /* XPKMASTER_XPKMASTER_H */
  261.